#!/usr/bin/env python

# Name: 	Configuration Manager
# Function:	- Read, parse and store arguments
#		  * Cue File
#		  * Quality Requirement

import CueReader

#-------------------------------------------------------------------------

class Quality:

    HIGH    = {"value" : 1, "str" : "HIGH"}
    MEDIUM  = {"value" : 2, "str" : "MEDIUM"}
    LOW     = {"value" : 3, "str" : "LOW"}

    QUALITY_MAPPING = { 1 : HIGH, \
                        2 : MEDIUM, \
                        3 : LOW }

    def __init__(self, qualityValue):
        if qualityValue < 1:
            qualityValue = 1
        elif qualityValue > 3:
            qualityValue = 3

        self.quality = Quality.QUALITY_MAPPING[qualityValue]

    def __str__(self):
        return self.quality["str"]

    def __getattr__(self, name):
        if name == "value":
            return self.quality["value"]
        else:
            return None

#-------------------------------------------------------------------------

class ConfMan:
    '''
    class ConfMan - Configuration Manager
    '''

    def __init__(self, cueFile = None, quality = Quality.HIGH["value"]):
        self.id3Tags = CueReader.Id3Tags()
        self.quality = Quality(quality)

        if not cueFile is None:
            try:
                f_cueFile = open(cueFile, 'r')          # open the cue file
                self.id3Tags.readCueFile(f_cueFile)     # read the cue file
                f_cueFile.close()                       # close the cue file
            except IOError:
                print "WARNING: CUE file %s cannot be open. Continue without CUE file." % (cueFile)

    def __getattr__(self, name):
        # read ID3 tags
        return self.id3Tags.__getattr__(name)

    def getTrackAttr(self, name, trackNum):
        return self.id3Tags.getTrackAttr(name, trackNum)

    def printOut(self):
        print "Quality:      " + str(self.quality)
        print
        print "CUE Information:"
        self.id3Tags.printOut()
